#include "stdafx.h"
#include "TestSuite.h"
#include "TestResult.h"

namespace JHCPP{
	namespace CppUnit{

		CTestSuite::CTestSuite(const std::string& name)
		: m_name(name)
		{
		}

		CTestSuite::~CTestSuite()
		{
			deleteContents();
		}

		void CTestSuite::run(CTestResult *result)
		{
			for (std::vector<CTest*>::iterator it = m_tests.begin(); it != m_tests.end(); ++it) 
			{
				if (result->shouldStop ())
					break;

				CTest *test = *it;
				test->run(result);
			}
		}

		int CTestSuite::countTestCases()
		{
			int count = 0;

			for (std::vector<CTest*>::iterator it = m_tests.begin (); it != m_tests.end (); ++it)
				count += (*it)->countTestCases();

			return count;
		}

		void CTestSuite::addTest(CTest* test)
		{
			m_tests.push_back(test);
		}

		std::string CTestSuite::toString()
		{
			return "suite " + m_name; 
		}

		const std::vector<CTest*> CTestSuite::tests() const
		{
			return m_tests;
		}

		void CTestSuite::deleteContents()
		{
			for (std::vector<CTest*>::iterator it = m_tests.begin(); it != m_tests.end(); ++it)
				delete *it;
		}

	}//end of namespace CppUnit
}//end of namespace JHCPP
